import { Component, OnInit } from '@angular/core';
import { SFCustomWidgetSchema, SFNumberWidgetSchema, SFRadioWidgetSchema, SFSchema, SFUISchema } from '@delon/form';
import { _HttpClient } from '@delon/theme';
import { NzMessageService } from 'ng-zorro-antd/message';
import { NzModalRef } from 'ng-zorro-antd/modal';

@Component({
  selector: 'app-supply-management-update-freight',
  templateUrl: './update-freight.component.html',
})
export class SupplyManagementUpdateFreightComponent implements OnInit {
  record: any = {};
  i: any;
  schema: SFSchema = {};
  ui: SFUISchema = {};
  constructor(
    private modal: NzModalRef,
    private msgSrv: NzMessageService,
    public http: _HttpClient,
  ) { }

  ngOnInit(): void {
    this.initSF();

    if (this.record.id > 0)
      this.http.get(`/user/${this.record.id}`).subscribe(res => (this.i = res));
  }
  initSF() {
    this.schema = {
      properties: {
        no1: {
          type: 'string',
          title: '是否回单',
          enum: [
            { label: '需要', value: 0 },
            { label: '不需要', value: 1 },
          ],
          ui: {
            widget: 'radio'
          } as SFRadioWidgetSchema,
          default: 0
        },
        owner1: {
          type: 'number',
          title: '预付',
          minimum: 0,
          max: 99999999,
          ui: {
            prefix: '￥',
            widgetWidth: 200,
            precision: 2,
            change: (val: any) => this.changeNumVal(val, 1)
          } as SFNumberWidgetSchema
        },
        callNo1: {
          type: 'number',
          title: '到付',
          minimum: 0,
          ui: {
            prefix: '￥',
            widgetWidth: 200,
            precision: 2,
            change: (val: any) => this.changeNumVal(val, 2)
          } as SFNumberWidgetSchema
        },
        // href1: {
        //   type: 'number',
        //   title: '油卡',
        //   minimum: 0,
        //   ui: {
        //     prefix: '￥',
        //     widgetWidth: 200,
        //     precision: 2,
        //     change: (val: any) => this.changeNumVal(val, 3)
        //   } as SFNumberWidgetSchema
        // },
        description5: {
          type: 'number', title: '回单付',  minimum: 0, maxLength: 140, ui: {
            prefix: '￥',
            widgetWidth: 200,
            precision: 2,
            change: (val: any) => this.changeNumVal(val, 4)
          } as SFNumberWidgetSchema
        },
        href2: {
          type: 'string',
          title: '小计',
          ui: {
            widget: 'text'
          }
        },
        description1: {
          type: 'string',
          title: '附加费',
          ui: {
            widget: 'custom'
          }
        },
        description2: {
          type: 'string',
          title: '总费用',
          ui: {
            widget: 'text'
          }
        },
        description3: {
          type: 'number',
          title: '到货后',
          maximum: 30,
          minimum: 1,
          ui: {
            widget: 'custom',
          } as SFCustomWidgetSchema
        },
      },
      required: ['owner', 'callNo', 'href', 'description'],
    };
    this.ui = {
      '*': {
        spanLabelFixed: 100,
        grid: { span: 16 },
      },
    };
  }
  save(value: any): void {
    this.http.post(`/user/${this.record.id}`, value).subscribe(res => {
      this.msgSrv.success('保存成功');
      this.modal.close(true);
    });
  }

  close(): void {
    this.modal.destroy();
  }
  /**
   * 更新数字框
   * @param value 
   * @param type 
   */
  changeNumVal(value: any, type: number) {

  }
}
